//---------------------------------------------------------------------
// This file is part of the Microsoft BizTalk Server 2006 SDK
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// This source code is intended only as a supplement to Microsoft BizTalk
// Server 2006 release and/or on-line documentation. See these other
// materials for detailed information regarding Microsoft code samples.
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
// KIND, WHETHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
// PURPOSE.
//---------------------------------------------------------------------
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Diagnostics;

namespace MsPartners.Unisys.BizTalkAdapters.AdapterWizard
{
	public class WzPageReceiveSetup : Microsoft.BizTalk.Wizard.WizardInteriorPage, IWizardControlInterface
	{
		private const string reqRspWarning = 
			"Using a regular adapter " +
			"for request-response is not advised. " +
			"Consider using an isolated adapter for this scenario.";
		public event AddWizardResultEvent addWizardResultEvent;

		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.TextBox txtRecvAdapterDesc;
		private System.Windows.Forms.GroupBox grpRecvType;
		private System.Windows.Forms.RadioButton chcIsolated;
		private System.Windows.Forms.RadioButton chcRegular;
		private System.Windows.Forms.CheckBox chkReqRspSupport;
		private System.Windows.Forms.ErrorProvider InfoProvider;
		private System.ComponentModel.IContainer components = null;

		public WzPageReceiveSetup()
		{
			// This call is required by the Windows Form Designer.
			InitializeComponent();

			// TODO: Add any initialization after the InitializeComponent call
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(WzPageReceiveSetup));
			this.chkReqRspSupport = new System.Windows.Forms.CheckBox();
			this.label1 = new System.Windows.Forms.Label();
			this.txtRecvAdapterDesc = new System.Windows.Forms.TextBox();
			this.grpRecvType = new System.Windows.Forms.GroupBox();
			this.chcIsolated = new System.Windows.Forms.RadioButton();
			this.chcRegular = new System.Windows.Forms.RadioButton();
			this.InfoProvider = new System.Windows.Forms.ErrorProvider(this.components);
			this.panelHeader.SuspendLayout();
			this.grpRecvType.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.InfoProvider)).BeginInit();
			this.SuspendLayout();
			// 
			// labelTitle
			// 
			resources.ApplyResources(this.labelTitle, "labelTitle");
			// 
			// labelSubTitle
			// 
			resources.ApplyResources(this.labelSubTitle, "labelSubTitle");
			// 
			// chkReqRspSupport
			// 
			resources.ApplyResources(this.chkReqRspSupport, "chkReqRspSupport");
			this.chkReqRspSupport.Name = "chkReqRspSupport";
			this.chkReqRspSupport.CheckedChanged += new System.EventHandler(this.chkReqRspSupport_CheckedChanged);
			// 
			// label1
			// 
			resources.ApplyResources(this.label1, "label1");
			this.label1.Name = "label1";
			// 
			// txtRecvAdapterDesc
			// 
			resources.ApplyResources(this.txtRecvAdapterDesc, "txtRecvAdapterDesc");
			this.txtRecvAdapterDesc.Name = "txtRecvAdapterDesc";
			// 
			// grpRecvType
			// 
			this.grpRecvType.Controls.Add(this.chcIsolated);
			this.grpRecvType.Controls.Add(this.chcRegular);
			resources.ApplyResources(this.grpRecvType, "grpRecvType");
			this.grpRecvType.Name = "grpRecvType";
			this.grpRecvType.TabStop = false;
			// 
			// chcIsolated
			// 
			resources.ApplyResources(this.chcIsolated, "chcIsolated");
			this.chcIsolated.Name = "chcIsolated";
			this.chcIsolated.CheckedChanged += new System.EventHandler(this.chcIsolated_CheckedChanged);
			// 
			// chcRegular
			// 
			this.chcRegular.Checked = true;
			resources.ApplyResources(this.chcRegular, "chcRegular");
			this.chcRegular.Name = "chcRegular";
			this.chcRegular.TabStop = true;
			this.chcRegular.CheckedChanged += new System.EventHandler(this.chcRegular_CheckedChanged);
			// 
			// InfoProvider
			// 
			this.InfoProvider.ContainerControl = this;
			resources.ApplyResources(this.InfoProvider, "InfoProvider");
			// 
			// WzPageReceiveSetup
			// 
			this.Controls.Add(this.chkReqRspSupport);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.txtRecvAdapterDesc);
			this.Controls.Add(this.grpRecvType);
			this.Name = "WzPageReceiveSetup";
			this.SubTitle = "Specify receive adapter settings";
			this.Title = "Receive side settings";
			this.Enter += new System.EventHandler(this.WzPageReceiveSetup_Enter);
			this.Load += new System.EventHandler(this.WzPageReceiveSetup_Load);
			this.Leave += new System.EventHandler(this.WzPageReceiveSetup_Leave);
			this.Controls.SetChildIndex(this.panelHeader, 0);
			this.Controls.SetChildIndex(this.grpRecvType, 0);
			this.Controls.SetChildIndex(this.txtRecvAdapterDesc, 0);
			this.Controls.SetChildIndex(this.label1, 0);
			this.Controls.SetChildIndex(this.chkReqRspSupport, 0);
			this.panelHeader.ResumeLayout(false);
			this.grpRecvType.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.InfoProvider)).EndInit();
			this.ResumeLayout(false);
			this.PerformLayout();

		}
		#endregion

		protected void AddWizardResult(string strName,string strValue)
		{
			PropertyPairEvent PropertyPair = new PropertyPairEvent(strName,strValue);
			OnAddWizardResult(PropertyPair);
		}

		// The protected OnRaiseProperty method raises the event by invoking 
		// the delegates. The sender is always this, the current instance 
		// of the class.
		protected virtual void OnAddWizardResult(PropertyPairEvent e)
		{
			if (e != null) 
			{
				// Invokes the delegates. 
				addWizardResultEvent(this,e);
			}
		}

		private void WzPageReceiveSetup_Leave(object sender, System.EventArgs e)
		{
			AddWizardResult(WizardValues.ReceiveAdapterDescription,txtRecvAdapterDesc.Text);
			AddWizardResult(WizardValues.ReceiveAdapterIsIsolated,chcIsolated.Checked.ToString());
			AddWizardResult(WizardValues.ReceiveAdapterSupportsReqRsp,chkReqRspSupport.Checked.ToString());
		}

		private void WzPageReceiveSetup_Enter(object sender, System.EventArgs e)
		{
			EnableNext(true);
		}

		private void WzPageReceiveSetup_Load(object sender, System.EventArgs e)
		{
#if DEBUG
			txtRecvAdapterDesc.Text = "Description for receive adapter";
#endif
			txtRecvAdapterDesc.Focus();		
		}

		private void chkReqRspSupport_CheckedChanged(object sender, System.EventArgs e)
		{
			if (chkReqRspSupport.Checked && chcRegular.Checked)
			{
				InfoProvider.SetError(chkReqRspSupport,reqRspWarning);
			}
			else
			{
				InfoProvider.SetError(chkReqRspSupport,"");
				InfoProvider.SetError(chcRegular,"");
			}
		}

		private void chcRegular_CheckedChanged(object sender, System.EventArgs e)
		{
			if (chkReqRspSupport.Checked && chcRegular.Checked)
			{
				InfoProvider.SetError(chcRegular,reqRspWarning);
			}
			else
			{
				InfoProvider.SetError(chcRegular,"");
				InfoProvider.SetError(chkReqRspSupport,"");
			}
		}

		private void chcIsolated_CheckedChanged(object sender, System.EventArgs e)
		{
			if (chcIsolated.Checked)
			{
				InfoProvider.SetError(chkReqRspSupport,"");
				InfoProvider.SetError(chcRegular,"");
			}
		}

		public bool NextButtonEnabled
		{
			get {	return true;	}
		}

		public bool NeedSummary
		{
			get {	return false;	}
		}
	}
}

